﻿@using ZBJF.Warranty.Common.Enums
@using ZBJF.Warranty.WebProvider
@{
    ViewBag.Title = "用户管理";
}
<div class="breadcrumbs" id="breadcrumbs">
    <ul class="nav nav-tabs">
        <li class="active"><a href="/System/Admin">用户列表</a></li>
    </ul>
</div>
<form id="searchForm" class="breadcrumb form-search">
    <div>
        <label>所属系统</label>
        @Html.DropDownList("BelongApplicationType", ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(ApplicationType)))
        <label>角色</label>
        @Html.DropDownList("RoleID", ConvertToSelector.Instance.RolesConvertToSelectList())
        <label>承保公司</label>
        @Html.TextBox("InsuranceCompanyName", "", new { @readonly = "readonly", @class = "select-icon", onclick = "showLayerOpen('选择承保公司','/PubModelDialog/InsuranceCompanySelector?chkStyle=radio','320px','60%&textid=InsuranceCompanyName&hiddenId=InsuranceCompanyID')" })
        @Html.Hidden("InsuranceCompanyID")
        <label>关键词</label>
        @Html.TextBox("Keyword", "", new { placeholder = "用户名或账号" })
        <input id="btnReset" class="btn Search-R form-reset" type="button" value="重置">
        <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="查询" onclick="search();">
    </div>
    <div class="margin-t-5">
        <a id="AddNewRole" class="btn btn-xs btn-primary Add-R" data-toggle="modal" href="" onclick="showLayerOpen('添加新用户','/System/admin/Edit/0','600px','450px')" title="添加新用户">
            <i class="icon-plus-sign bigger-130"></i>
            添加新用户
        </a>
    </div>
</form>
<table id="adminTable" class="table table-striped table-bordered table-hover">
    <thead>
        <tr>
            <th width="50">序号</th>
            <th>用户名</th>
            <th>账号</th>
            <th>角色</th>
            <th>所属系统</th>
            <th>承保公司</th>
            <th>承保公司分公司</th>
            <th>创建时间</th>
            <th>是否可登陆</th>
            <th width="150">
                操作
            </th>
        </tr>
    </thead>
</table>
@section scripts{
    @Scripts.Render("~/bundles/chosen")
    @Styles.Render("~/Content/chosen")
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
    <script type="text/javascript">
        $(function () {
            $("#RoleListID").chosen();
            var objTable = $("#adminTable").dataTable({
                fnDrawCallback: function () {
                    ControlPermissionOperate();
                },
                "aaSorting": [[7, "desc"]],
                aoColumns: [
                    {
                        "mData": null,
                        "bSortable": false,
                        "fnRender": function (nRow) {
                            return nRow.iDataRow + 1;
                        }
                    },
                    { "mData": "UserDisPlayName" },
                    { "mData": "UserAccount" },
                    { "mData": "RoleNames" },
                    { "mData": "BelongApplicationType" },
                    { "mData": "ParentCompanyName" },
                    { "mData": "CompanyName" },
                    { "mData": "CreateTime" },
                    {
                        "mData": null,
                        fnRender: function (nRow) {
                            return nRow.aData.IsAvailable ? bootStrapOkIncon : bootStrapRemoveIncon;
                        }
                    },
                    {
                        "mData": null,
                        "bSortable": false,
                        fnRender: function (nRow) {
                            var html = "<a class=\"green Edit-R\" href=\"javascript:showLayerOpen('编辑用户','/System/Admin/Edit/" + nRow.aData.ID + "','500px','400px')\" title=\"编辑\"><i class=\"icon-pencil bigger-130\"></i></a>"; //编辑
                            html += "<a class=\"green Edit-R\" href=\"javascript:UpdateStatus('" + nRow.aData.ID + "'," + !nRow.aData.IsAvailable + ",'/System/admin/UpdateStatus','adminTable')\" title=\"" + (nRow.aData.IsAvailable ? "禁用" : "启用") + "\">" + (nRow.aData.IsAvailable ? bootStrapRemoveIncon : bootStrapOkIncon) + "</a>";
                            html += "<a class=\"red Edit-R\" href=\"javascript:ShowResetPSWswDialog('" + nRow.aData.ID + "')\" title=\"重置密码\"><i class=\"icon-refresh bigger-130\"></i></a>";
                            html += "<a href=\"javascript:showLayerOpen('设置用户角色','/System/Admin/SystemUserToRoleMapping?UserID=" + nRow.aData.ID + "','600px','400px')\" class=\"Edit-R LookActionRole\" title=\"设置角色\"><i class=\"icon-user green bigger-120\"></i></a>";
                            return html;
                        }
                    }
                ],
                "sAjaxSource": "/System/Admin/"
            });
        });

        function search() {
            /*给查询对象赋值*/
            queryParamList.BelongApplicationType = String($("#BelongApplicationType").val());
            queryParamList.RoleID = String($("#RoleID").val());
            queryParamList.InsuranceCompanyID = String($("#InsuranceCompanyID").val());
            queryParamList.Keyword = String($("#Keyword").val());
            $("#adminTable").dataTable().fnDraw();
        }

        function RestPassWord(id, password) {
            $.ajax({
                type: "post",
                data: { id: id, newPassWord: password },
                url: "/System/Admin/RestPassWord",
                success: function (result) {
                    if (result.success) {
                        var index = layer.alert(result.message, {
                            yes: function () {
                                reloadTable("adminTable");
                                layer.close(index);
                            }
                        });
                    } else {
                        layer.alert(result.message);
                    }
                }
            });
        }

        function ShowResetPSWswDialog(id) {
            layer.prompt("请输入新的密码", function (result) {
                if (result == null) {

                } else if (result == "" || result.length < 6) {
                    var index = layer.alert(result.message, {
                        yes: function () {
                            ShowResetPSWswDialog(id);
                            layer.close(index);
                        }
                    });
                } else {
                    RestPassWord(id, result);
                }
            });
        }
    </script>
}
